package org.example.controller;

import com.bianmaba.commons.annotation.WrapResult;
import com.bianmaba.spring.mvc.annotation.RequestResponseBodyConfig;
import com.bianmaba.spring.mvc.config.annotation.EntityParam;
import org.example.bean.entity.Order;
import org.example.bean.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @program: example-spring-boot-extend
 * @description:
 * @author: Chenjiabin
 * @create: 2019/4/10 18:01
 **/
@Controller
@RequestMapping("simple")
public class SimpleController extends ExceptionControllerSupport {
    @RequestMapping("simple")
    @WrapResult
    public Object sample(User user) {
        return user;
    }

    @WrapResult
    @RequestMapping("filter")
    @RequestResponseBodyConfig(excludeProperties = {"exception", "data.*\\.id"})
    public Object filter() {
        User user = new User();
        user.setId("id");
        user.setName("name");
        user.setUsername("username");
        user.setPassword("password");
        user.addOrder(new Order("id", "name"));
        return user;
    }

    @WrapResult
    @RequestMapping("resolve_entity_argument")
    public Object resolveArgument(@EntityParam User user, @EntityParam User user1, String test) {
        return createResult(user, user1, test);
    }

    @WrapResult
    @RequestMapping("resolve_entity_list_argument")
    public Object resolveArgument(@EntityParam ArrayList<User> users, @EntityParam ArrayList<User> users1, String test) {
        return createResult(users, users1, test);
    }

    @WrapResult
    @RequestMapping("resolve_entity_array_argument")
    public Object resolveArgument(@EntityParam User[] users, @EntityParam User[] users1, String test) {
        return createResult(users, users1, test);
    }

    @WrapResult
    @RequestMapping("resolve_entity_map_argument")
    public Object resolveArgument(@EntityParam Map<String, User> users, @EntityParam Map<String, User> users1, String test) {
        return createResult(users, users1, test);
    }

    @WrapResult
    @RequestMapping("resolve_entity_set_argument")
    public Object resolveArgument(@EntityParam Set<User> users, @EntityParam Set<User> users1, String test) {
        return createResult(users, users1, test);
    }

    private Object createResult(Object users, Object users1, String test) {
        Map<String, Object> result = new HashMap<String, Object>(0);
        result.put("users", users);
        result.put("users1", users1);
        result.put("test", test);
        return result;
    }
}
